Skip to content

Enable Mypy strict mode - #9803

Open
akx wants to merge 7 commits into
python-pillow:mainfrom
akx:strict-typing-v2
Open

Enable Mypy strict mode#9803
akx wants to merge 7 commits into
python-pillow:mainfrom
akx:strict-typing-v2

Conversation

@akx

@akx akx commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Rebase of #9410, with the type fixes reduced to the minimum required to make uvx --python=3.11 --with-requirements=.ci/requirements-mypy.txt mypy conftest.py selftest.py setup.py checks docs src winbuild Tests pass. Most of the conflicts there were post f80b914 merge.

Closes #9410.

@akx
akx force-pushed the strict-typing-v2 branch from 372de56 to 9b1659a Compare July 20, 2026 12:44
@akx
akx marked this pull request as ready for review July 20, 2026 12:44
@radarhere

radarhere commented Jul 20, 2026

Copy link
Copy Markdown
Member

Given that this is considerably smaller than #9410, I suspect you're only fixing the strict mode problems that arose testing against Python 3.11.

#9410 had its sights set a bit higher - it actually wanted to correct strict mode problems for newer versions of Python as well, which fell into an unresolved debate about whether to test against those versions or not.

But that isn't necessarily something to stop this PR from being merged. I just suspect it doesn't exactly replace #9410.

@akx

akx commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Same result on all supported Pythons.

$ for py in 3.11 3.12 3.13 3.14; uvx -q --python=$py --with-requirements=.ci/requirements-mypy.txt mypy conftest.py selftest.py setup.py checks docs src winbuild Tests; end
Success: no issues found in 303 source files
Success: no issues found in 303 source files
Success: no issues found in 303 source files
Success: no issues found in 303 source files
$

@radarhere

Copy link
Copy Markdown
Member

radarhere@cfb3ab8 added to these changes gives failures on 3.12 - 3.14.

@akx
akx force-pushed the strict-typing-v2 branch from 52a7a80 to 35af1ef Compare July 22, 2026 05:34
@radarhere radarhere mentioned this pull request Jul 27, 2026
@akx akx mentioned this pull request Jul 29, 2026
@akx
akx force-pushed the strict-typing-v2 branch from cc0b191 to 0c2f232 Compare August 10, 2026 18:45
jorenham and others added 2 commits August 12, 2026 17:11
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Aarni Koskela <akx@iki.fi>
@akx
akx force-pushed the strict-typing-v2 branch from 0c2f232 to 20615d7 Compare August 12, 2026 14:11
@akx
akx force-pushed the strict-typing-v2 branch from 9d6a2b9 to 4ce1298 Compare August 12, 2026 14:13
Comment thread .github/workflows/lint.yml Outdated
Comment thread .github/workflows/lint.yml Outdated
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@akx
akx requested a review from radarhere August 16, 2026 12:03
fail-fast: false
matrix:
python-version: [
"3.14",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self - it appears apache/arrow#48172 is blocking 3.15 support

@radarhere

Copy link
Copy Markdown
Member

A review was requested, so I'll restate - the fundamental issue here isn't any implementation detail, it's the question of whether we should do this - #9414 (comment)

Do we really need to run mypy on every version? Should we run on the oldest supported, or latest? Is there authoritative guidance on best practices here?

python/mypy#12286 is an issue requesting the ability to check multiple versions at once. From the fact that it is still open, you might infer that this isn't an official priority.

#9410 (comment)

I don't think we have any "official" recommendations on this. But unofficially we recommend:

  • Always run mypy on the oldest supported Python version.
  • If your code has known platform-specific logic (e.g. Linux vs Windows), run the above on as many platforms as needed.
  • You may also run mypy on the newest supported Python version (in this case it makes sense to use --enable-error-code=deprecated to see deprecations early).

@hugovk

hugovk commented Aug 17, 2026

Copy link
Copy Markdown
Member

I'm also not sure if we need to enable strict mode, some of our annotations are pretty complex already and I don't think the EpsImagePlugin.py and GifImagePlugin.py changes improve readability.

The ImageGrab.py fix is needed for macOS with the current config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants